package models;

import easyDAO.SqlDispatch;

/**
 * Created by yangxianming on 2022/6/22.
 */
public class GetPageCount {
    MyConfig myConfig;
    public GetPageCount(MyConfig myConfig){
        this.myConfig = myConfig;
    }

    public Integer getCount(String sqlWord){
        SqlDispatch sqlDispatch = new SqlDispatch(myConfig);
        SqlReturnModel sqlReturnModel = sqlDispatch.selectWord(sqlWord);
        if (sqlReturnModel.getIsSuccess()){
            String strCount = sqlReturnModel.getSelectReturnData().get(0).get(0);
            return Integer.valueOf(strCount);
        }else {
            return -1;
        }
    }

    public String getLimit(Integer toPage, Integer everyPage){
        //组装这条语句  limit 300, 15
        toPage = toPage - 1;  //前端需要跳转第几页
        int nowPageFrom = toPage * everyPage;                                        //通过每页个数，算出数据库起始行号
        return " limit " + nowPageFrom + ", " + everyPage;
    }
}
